﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace YFrameWork.RunTime
{
    public class UIGroup:MonoBehaviour
    {
        private RectTransform rect;
        public Dictionary<UIFormType, UIForm> AllUIFormDic = new Dictionary<UIFormType, UIForm>();

        public int CurrentChildCount => transform.GetSiblingIndex();


        public RectTransform Rect { get => rect;  }

        public void Init(RectTransform _rect)
        {
            rect = _rect;
            rect.localScale = Vector3.one;
            rect.anchorMin = Vector2.zero;
            rect.anchorMax = Vector2.one;
            rect.sizeDelta = Vector2.zero;
            rect.localPosition = Vector3.zero;
        }
        public virtual bool AddUIForm(UIFormType uIFormType,UIForm uIForm) 
        {
            if (!AllUIFormDic.ContainsKey(uIFormType))
            {
                AllUIFormDic.Add(uIFormType, uIForm);
                RectTransform tran = uIForm.transform.GetComponent<RectTransform>();
                uIForm.transform.SetParent(transform);
                tran.localScale = Vector3.one;
                tran.anchorMin = Vector2.zero;
                tran.anchorMax = Vector2.one;
                tran.sizeDelta = Vector2.zero;
                uIForm.transform.localPosition = Vector3.zero;
                return true;
            }
            return false;
        }


        public virtual void RemoveUIForm(UIFormType uIFormType)
        {
            if (AllUIFormDic.ContainsKey(uIFormType))
            {
                AllUIFormDic.Remove(uIFormType);
            }
        }

    }
}